package com.szqhyxj.youxiangju.biz.set.changepassword;

import android.text.TextUtils;

import com.szqhyxj.youxiangju.sys.BaseResult;
import com.szqhyxj.youxiangju.sys.RetrofitFacade;

import java.util.HashMap;

import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

public class ChangePassWordModel {

    public interface ChangePassWordService{
        @FormUrlEncoded
        @POST("msg/sms/resetPwd")
        Observable<BaseResult> changePasswordSms(@Field("phone") String phone);

        @FormUrlEncoded
        @POST("user/pwd/reset")
        Observable<BaseResult> commit(
                @Field("useraccount") String useraccount,
                @Field("loginPwd") String loginPwd,
                @Field("validCode") String validCode

        );
    }


    public static Observable<BaseResult> sms(ChangePasswordEntity changePasswordEntity) {
        return RetrofitFacade.Companion.getRetrofit()
                .create(ChangePassWordService.class)
                .changePasswordSms(
                     changePasswordEntity.getUseraccount()
                );
    }
    public static Observable<BaseResult> commit(ChangePasswordEntity changePasswordEntity){
        return RetrofitFacade.Companion.getRetrofit()
                .create(ChangePassWordService.class)
                .commit(
                        changePasswordEntity.getUseraccount(),
                        changePasswordEntity.getLoginPwd(),
                        changePasswordEntity.getValidCode()
                );
    }
    public static class ChangePasswordEntity{
        private String loginPwd;
        private String validCode;
        private String useraccount;

        public ChangePasswordEntity(String loginPwd, String validCode, String useraccount, String registerVerifyPassword, Boolean agree) {
            this.loginPwd = loginPwd;
            this.validCode = validCode;
            this.useraccount = useraccount;
            this.registerVerifyPassword = registerVerifyPassword;
            this.agree = agree;
        }
        public ChangePasswordEntity(){

        }

        private String registerVerifyPassword;
        private Boolean agree;

        public String getRegisterVerifyPassword() {
            return registerVerifyPassword;
        }

        public void setRegisterVerifyPassword(String registerVerifyPassword) {
            this.registerVerifyPassword = registerVerifyPassword;
        }

        public Boolean getAgree() {
            return agree;
        }

        public void setAgree(Boolean agree) {
            this.agree = agree;
        }


        public boolean valid () {
            return !TextUtils.isEmpty(this.useraccount)
                    && !TextUtils.isEmpty(this.validCode)
                    && !TextUtils.isEmpty(this.loginPwd)
                    && loginPwd.equals(registerVerifyPassword);

        }
        public boolean valid1 () {
            return !TextUtils.isEmpty(this.useraccount)
                    && !TextUtils.isEmpty(this.validCode)
                    && !TextUtils.isEmpty(this.loginPwd)
                    && loginPwd.equals(registerVerifyPassword)
                    && this.agree;

        }
        public void setLoginPwd(String loginPwd){
            this.loginPwd = loginPwd;
        }

        public String getLoginPwd(){
            return loginPwd;
        }

        public void setValidCode(String validCode){
            this.validCode = validCode;
        }

        public String getValidCode(){
            return validCode;
        }

        public void setUseraccount(String useraccount){
            this.useraccount = useraccount;
        }

        public String getUseraccount(){
            return useraccount;
        }


    }
}